VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Find any part of a string in a ListView. Click Go > to continue to next occurence

by Sly (2 Submissions)
Category: Miscellaneous
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Fri 22nd December 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Find any part of a string in a ListView. Click Go > to continue to next occurence

API Declarations


Add a Command Button - cmdGo Caption - Go >
To find next, click Go > again

Rate Find any part of a string in a ListView. Click Go > to continue to next occurence



  txtFind_Lookup
End Sub


Private Sub txtFind_Lookup()
Dim lvwItm   As ListItem
Dim Itm      As Integer
Dim SubItm   As Integer
Dim strSrch    As String

If txtFind > "" Then
Set lvwItm = ListView1.FindItem(txtFind.Text, , , lvwPartial) 'Search Items
doagain:
If lvwItm Is Nothing Then   ' Search Subitems
Itm = 0: SubItm = 0
For Itm = LastItm To ListView1.ListItems.Count
 
  If InStr(1, UCase(ListView1.ListItems.Item(Itm)), UCase(txtFind.Text)) Then
    Set lvwItm = ListView1.ListItems.Item(Itm)
    GoTo Out01
  End If
 
 For SubItm = 1 To 10  'Search first 10 Subitems CHANGE AS NEEDED
    strSrch = ListView1.ListItems.Item(Itm).ListSubItems.Item(SubItm).Text
  If InStr(1, UCase(strSrch), UCase(txtFind.Text)) Then
    Set lvwItm = ListView1.ListItems.Item(Itm)
    GoTo Out01
  End If
 Next SubItm
Next Itm
LastItm = Itm
If LastItm >= ListView1.ListItems.Count Then LastItm = 1: GoTo doagain
Exit Sub  'Not found
Out01:
LastItm = Itm + 1
If LastItm > ListView1.ListItems.Count Then LastItm = 1
    lvwItm.EnsureVisible
    lvwItm.Selected = True
    ListView1.SetFocus

Else
    lvwItm.EnsureVisible
    lvwItm.Selected = True
    ListView1.SetFocus

End If
End If

End Sub


Download this snippet    Add to My Saved Code

Find any part of a string in a ListView. Click Go > to continue to next occurence Comments

No comments have been posted about Find any part of a string in a ListView. Click Go > to continue to next occurence. Why not be the first to post a comment about Find any part of a string in a ListView. Click Go > to continue to next occurence.

Post your comment

Subject:
Message:
0/1000 characters